import 'package:boss/provider/commodity_provider.dart';
import 'package:boss/ui/page/commodity/categories/page/plusCommodityMode/page/plusCommodityByFormField/plus_commodity_by_form_field_page.dart';
import 'package:boss/ui/page/commodity/categories/page/plusCommodityMode/page/plusCommodityByFormField/provider/plus_commodity_by_form_provider.dart';
import 'package:boss/ui/widget/button/fixed_bottom_double_btn.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PlusCommodityByFormFieldFooter extends StatelessWidget {
  Future<bool> plusCommodity(BuildContext context) async {
    var plusCommodityByFormProvider = Provider.of<PlusCommodityByFormProvider>(context, listen: false);
    var commodityProvider = Provider.of<CommodityProvider>(context, listen: false);

    return commodityProvider.saveCommodity(
      plusCommodityByFormProvider.commodity,
      oldStoreMenu: plusCommodityByFormProvider.oldMenu,
    );
  }

  @override
  Widget build(BuildContext context) {
    return FixedBottomDoubleBtn(
      second: '继续新增',
      onFirst: () async {
        if (await plusCommodity(context)) {
          Navigator.pop(context);
        }
      },
      onSecond: () async {
        if (await plusCommodity(context)) {
          Navigator.popAndPushNamed(context, PlusCommodityByFormFieldPage.pageName);
        }
      },
    );
  }
}
